package com.feeyo.groundservice.vehiclemonitorserver;

import javax.mail.MessagingException;
import javax.mail.internet.AddressException;

import io.vertx.core.AbstractVerticle;
import io.vertx.core.Future;

public class AlarmService extends AbstractVerticle{
	public static long startTime = 0;
	public static int count = 0;
	boolean switching = false;
	
	 @Override
	    public void start(Future<Void> startFuture){
		 long usedTime = (System.currentTimeMillis()-startTime)/1000;
         if(usedTime > 60){
             System.out.println("receive data-------->>>>>>>>>>>>>"+count);
             if (count <100){
            	 if(!switching){
            		 //发送邮件报警
            		 switching = true;
            		 try {
						Mail.sendMail("车辆平台数据中断", "请及时修复");
					} catch (AddressException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					} catch (MessagingException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
            	 }
             }else{
            	 if(switching){
            		 //发送邮件解除报警
            		 switching = false;
            		 try {
						Mail.sendMail("车辆平台数据恢复", "车辆平台数据已恢复");
					} catch (AddressException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					} catch (MessagingException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
            	 }
             }
             count = 0;
             startTime = System.currentTimeMillis();
             
         }
	 }
}
